package com.livestocksolutions;

import java.util.Date;

import com.livestocksolutions.util.UpdateHistory;

/* -- Version History --
 *  1.0 : 13 July 2012 - Initial version.
 *  
 *  1.1 : 16 July 2012 - Class now implements Serializable
 *  
 *  1.2 : 19 September 2012 - added extra Constructor to accept a date.
 *  
 *  1.3 : 24 September 2012 - Parent Class no longer implements Serializable
 *  
 *  2.0 : 07 January 2012 - Moved CVD from Feed class to FeedHistory class.
 */

/**
 * This class provides a history use for a Feed.
 * @author Adam Parr
 * @version 2.0
 * 
 * @.modified 7 January 2012
 */
public class FeedHistory extends UsableItemHistory {
	
	/**
	 * Create a feeds usage history
	 * @param feed the feed to add 
	 * @param quantity amount of the feed used
	 * @param measurement units the quantity is measured in
	 */
	public FeedHistory(Feed feed, double quantity, String measurement) {
		super(feed, quantity, measurement);
	}
	
	/**
	 * Create a feeds usage history
	 * @param feed the feed to add 
	 * @param quantity amount of the feed used
	 * @param measurement units the quantity is measured in
	 * @param date The date this Feed was used.
	 */
	public FeedHistory(Feed feed, double quantity, String measurement, Date date) {
		super(feed, quantity, measurement, date);
	}
	
	/**
	 * Commodity vendor declaration number 
	 */
	private String cvdNumber;
	
	/**
	 * Get the commodity vendor declaration number of this feed
	 * @return cvd number associated with this feed
	 */
	public String getCVDNumber(){
		return cvdNumber;
	}
	
	/**
	 * Set the cvd Number for this feed
	 * @param cvdNumber commodity vendor declaration number of this feed
	 */
	public void setCVDNumber(String cvdNumber){
		if(cvdNumber!=null){
			this.cvdNumber=cvdNumber;
			update.put("CVD", new UpdateHistory(cvdNumber));
		}
	}
	
	/**
	 * Updates this Object with the updated values from the different version.
	 * @param changes FeedHistory that represents this Object in a different version.
	 * @return <tt>true</tt> if changes is not null and changes does not equal this object, <tt>false</tt> otherwise.
	 */
	public boolean update(FeedHistory changes){
		if(changes!=null && this!=changes){
			super.update(changes);
			
			if(updateBefore("CVD",changes)){
				cvdNumber=changes.update.get("CVD").getValue();
				update.put("CVD", new UpdateHistory(cvdNumber));
			}
			return true;
		}
		return false;
	}
}
